#include <iostream>

using namespace std;
class Animal
{
public:
	virtual void eat()
	{
		cout<<"动物吃"<<endl;
	}
};

class Dog:public Animal
{
public:
	void eat()
	{
		cout<<"狗吃骨头"<<endl;
	} 
};

class Sheep:public Animal
{
public:
	void eat()
	{
		cout<<"羊吃草"<<endl;
	} 
};
class Cat:public Animal
{
public:
	void eat()
	{
		cout<<"猫吃鱼"<<endl;
	} 
};

/* void animalEat(Sheep &sheep)  //参数不具备通用性
void animalEat(Cat &cat) 
void animalEat(Dog &dog) 
{
	sheep.eat();
}

C++允许  父类的指针或者父类的引用指向子类对象 */
void animalEat(Animal &animal) //希望具有通用性
{
	animal.eat();
}
int main()
{
	Cat cat;
	Dog dog;
	Sheep sheep;
	animalEat(cat);  //Animal &animal=cat;
	/* Animal &ani1=cat;
	animalEat(ani1);
	
	Animal &ani2=dog;
	animalEat(ani2);
	
	Animal &ani3=sheep;
	animalEat(ani3); */
}
